package com.tcm.smarthealth.controller;

import com.tcm.smarthealth.common.ApiResponse;
import com.tcm.smarthealth.common.exception.BusinessException;
import com.tcm.smarthealth.dto.UserProfileResponse;
import com.tcm.smarthealth.security.AuthContext;
import com.tcm.smarthealth.security.AuthenticatedUser;
import com.tcm.smarthealth.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户管理", description = "用户信息相关接口")
@RestController
@RequestMapping("/api/v1/users")
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @Operation(summary = "获取当前用户信息")
    @GetMapping("/me")
    public ApiResponse<UserProfileResponse> currentUser() {
        AuthenticatedUser user = AuthContext.getCurrentUser();
        if (user == null) {
            throw new BusinessException(HttpStatus.UNAUTHORIZED, "用户未登录");
        }
        UserProfileResponse profile = userService.getProfile(user.getId());
        return ApiResponse.success(profile);
    }
}

